import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const config = loadEnv(mode, './');
  return {
    plugins: [react()],

    css: {
      preprocessorOptions: {
        scss: {
          additionalData: ` @use "@/assets/scss/_vars.scss" as * ;`,
        },
      },
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
      },
    },
    // http://127.0.0.1:8504/ip-admin-api
    server: {
      host: true,
      // port: 5173,
      // host: '127.0.0.1',
      proxy: {
        '/api': {
          target: config.VITE_BASE_URL, // 会自动判断当前环境，对应上述三个文件中的target
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  };
});
